<%@ page pageEncoding="UTF-8"%>
<%@ include file="../commons/head.jsp"%>
<title>会员账户报表</title>
<style type="text/css">
	.button{width: 100px;height: 30px;margin:3px 20px 3px 0;padding-top: 3px;}
	*{font-size: 14px;}
	.th td{font-weight: 700;}
	/* label{margin: 0 10px 0 18px;font-weight: 500;height: 25px;line-height: 25px;} */
     .control-label{padding: 0;font-weight: bold;}
     .diaform{margin: 20px auto;}
     h3{border-bottom:1px solid #ddd;padding-bottom:5px;width: 98%;  }
     .datagrid-view{border-top:1px solid #ddd;margin-top: 8px;}
     .datagrid-pager{border-bottom:1px solid #ccc;}
     hr{margin:15px 0 13px 0 ;background-color: #ddd;height: 1px;border: 0; width: 120%;}
     .jianju{margin-left:15px; }
     .datagrid-htable{
     font-weight:bold;
	/* background-color: #148CCA; */
	}
	.demo_line_01{
    
    margin: 5px 0;
    font-size: 50px;
    line-height: 1px;
    text-align: center;
	}
	.demo_line_01 .line{
	display:inline-block;
	   width:47.8%;
	   height:1px;
	   background:#ddd;
	   vertical-align:middle;
	   margin-top:8px;
	}
	.container-fluid{
	padding-left: 15px;
	}
	.datagrid-ftable td div{
		font-size: larger;
	
	}
	#pulldown{
		margin-top: 20px;
	}
	
/* td.datagrid-header-over{
	background: #148CCA !important;
} */

.datagrid-ftable {
	color: red;
	font-weight: bold;
}
.datagrid-body {
height:300px !important;
}
.datagrid-view {
height:360px !important;
}

</style>

<script type="text/javascript">
var isValid;
var helpType;
var data;
var flag=0;
var queryInit = true ;
var loginAccount = 'baidd';
	
$(function(){
	function scrollShow(datagrid) {
	    datagrid.prev(".datagrid-view2").children(".datagrid-body").html("<div style='width:" + datagrid.prev(".datagrid-view2").find(".datagrid-header-row").width() + "px;border:solid 0px;height:1px;'></div>");
	};
	scrollShow($("#tt"));
	//开单中心下拉框
	$('#kdzx').combobox({
		onLoadSuccess : function() {
			var data = $('#kdzx').combobox('getData');
			if (data) {
				$("#kdzx").combobox('select', data[0].userAccount);
			}
		}
	});
	
	$("#search").click(function(){debugger
		queryInit = false;
		var params = {
			startTime:$("#startTime").datebox('getValue'),
			endTime:$("#endTime").datebox('getValue'),
			tel:$("#tel").val(),
			name:$("#kdzx").val(),
			memberName:$("#memberName").val()
		};
		$("#tt").datagrid({url:"${ctx}/memberaccount/list",queryParams:params});
		init();
		
	});
	
	$("#drop").click(function(){
		if($("#pulldown").css("display")=="none"){
			$("#pulldown").show(500);
			$(this).removeClass("glyphicon-download");
			$(this).addClass("glyphicon-upload");
		}else{
			$("#pulldown").hide(500);
			$(this).addClass("glyphicon-download");
			$(this).removeClass("glyphicon-upload");
		}
		setTimeout(function(){  
	    	$(".datagrid-wrap").css("height",window.innerHeight+'px');
	    },500);
	});
	
});	


$(function(){
/* 导出 */
	$("#export").click(function(){
		var params = {
			startTime:$("#startTime").datebox('getValue'),
			endTime:$("#endTime").datebox('getValue'),
			name:$("#kdzx").val(),
			tel:$("#tel").val(),
			memberName:$("#memberName").val(),
		};
		
		window.location.href="${ctx}/memberaccount/export?tel="+params.tel
				+"&startTime="+encodeURI(params.startTime)
				+"&endTime="+encodeURI(params.endTime)
				+"&memberName="+params.memberName
				+"&name="+encodeURI(params.name)
				;
		
	});

});	

function init(){debugger
	var params = {
		startTime:$("#startTime").datebox('getValue'),
		endTime:$("#endTime").datebox('getValue'),
		name:$("#kdzx").val(),
		tel:$("#tel").val(),
		memberName:$("#memberName").val(),
	};
	 $.ajax({
		url : "${ctx}/memberaccount/listSUM",
		type : "get",
		data : params,
		cache : false,
		success : function(data) {debugger
			if(data != null && data != ""){
				$("#totalSum").text(data.totalSum);
				$("#avaibleSum").text(data.avaibleSum);
				$("#cusumeSum").text(data.cusumeSum);
				$("#investmentSum").text(data.investmentSum);
				$("#taxSum").text(data.taxSum);
				$("#rechagreSum").text(data.rechagreSum);
				$("#recommendSum").text(data.recommendSum);
				$("#a1Sum").text(data.a1Sum);
				$("#a2Sum").text(data.a2Sum);
				$("#a3Sum").text(data.a3Sum);
				$("#b1Sum").text(data.b1Sum);
				$("#b2Sum").text(data.b2Sum);
				$("#b3Sum").text(data.b3Sum);
				$("#dpBackSum").text(data.dpBackSum);
				
				memberEcharts();
			}else{
				$("#totalSum").text(0);
				$("#avaibleSum").text(0);
				$("#cusumeSum").text(0);
				$("#investmentSum").text(0);
				$("#taxSum").text(0);
				$("#rechagreSum").text(0);
				$("#recommendSum").text(0);
				$("#a1Sum").text(0);
				$("#a2Sum").text(0);
				$("#a3Sum").text(0);
				$("#b1Sum").text(0);
				$("#b2Sum").text(0);
				$("#b3Sum").text(0);
				$("#dpBackSum").text(0);
				memberEcharts();
				
			}
		}
		
	}); 
}
function memberEcharts(){
	var myChart = echarts.init(document.getElementById('member-echarts'));
	  var option = {
			    title : {
			        text: '会员账户表Income饼状图',
			        subtext: '',
			        x:'center'
			    },
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    },
			    legend: {
			        orient: 'vertical',
			        left: 'left',
			        data: ['总收入','余额','乐花','贴心宝','税费','充值金额','推荐奖','A1奖','A2奖','A3奖','B1奖','B2奖','B3奖','死点返还']
			    },
			    series : [
			        {
			            name: '会员账户',
			            type: 'pie',
			            radius : '55%',
			            center: ['60%', '40%'],
			            data:[
			                {value:parseInt($("#totalSum").text()), name:'总收入'},
			                {value:parseInt($("#avaibleSum").text()), name:'余额'},
			                {value:parseInt($("#cusumeSum").text()), name:'乐花'},
			                {value:parseInt($("#investmentSum").text()), name:'贴心宝'},
			                {value:parseInt($("#taxSum").text()), name:'税费'},
			                {value:parseInt($("#rechagreSum").text()), name:'充值金额'},
			                {value:parseInt($("#recommendSum").text()), name:'推荐奖'},
			                {value:parseInt($("#a1Sum").text()), name:'A1奖'},
			                {value:parseInt($("#a2Sum").text()), name:'A2奖'},
			                {value:parseInt($("#a3Sum").text()), name:'A3奖'},
			                {value:parseInt($("#b1Sum").text()), name:'B1奖'},
			                {value:parseInt($("#b2Sum").text()), name:'B2奖'},
			                {value:parseInt($("#b3Sum").text()), name:'B3奖'},
			                {value:parseInt($("#dpBackSum").text()), name:'死点返还'}
			            ],
			            itemStyle: {
			                emphasis: {
			                    shadowBlur: 10,
			                    shadowOffsetX: 0,
			                    shadowColor: 'rgba(0, 0, 0, 0.5)'
			                }
			            }
			        }
			    ]
			}; 
	 myChart.setOption(option); 
}

function reload(closeFlag){
	if(reloadFlag){
		$("#fm").form('clear');
	}
	if(closeFlag){
		$("#dlg").dialog('close');
	}
	$("#tt").datagrid('reload');
} 

 function closeDlg(){
	$("#tt").datagrid('reload');
	$('#dlg').dialog('close');
}; 

function rowStyle(index,row){
	if (index%2==0){     
        return 'background-color:lightcyan;';     
    }     
}

$(function(){
    $("#tel").textbox('textbox').bind('keyup', function(e){
	        $("#tel").textbox('setValue', $(this).val().replace(/\D/g,''));
    });
});

function formatMoney(number) {
number = Math.round(number * 100) / 100;
return outputDollars(Math.floor(number - 0) + '') + outputCents(number - 0);
}
function outputDollars(number) {
if (number.length <= 3)
	return (number == '' ? '0' : number);
else {
	var mod = number.length % 3;
	var output = (mod == 0 ? '' : (number.substring(0, mod)));
	for (i = 0; i < Math.floor(number.length / 3); i++) {
		if ((mod == 0) && (i == 0))
			output += number.substring(mod + 3 * i, mod + 3 * i + 3);
		else
			output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
	}
	return (output);
}
}
function outputCents(amount) {
amount = Math.round(((amount) - Math.floor(amount)) * 100);

if (amount == 10 || amount == 20 || amount == 30 || amount == 40
		|| amount == 50 || amount == 60 || amount == 70 || amount == 80
		|| amount == 90) {
	amount = (amount.toString()).substr(0, (amount.toString()).length - 1);
	return '.' + amount;
} else if (amount == 0) {
	return "";
} else if (amount == 1 || amount == 2 || amount == 3 || amount == 4
		|| amount == 5 || amount == 6 || amount == 7 || amount == 8
		|| amount == 9) {
	return '.0' + amount;
} else {
	return '.' + amount;
}

}
//鼠标悬停显示提示
function showTips(value, row, index) {
	var content = '';
	if(value != null && value != ''){
	    if(value.length>6 && strDateTime(value)){ //如果为时间
			value = value.substr(0,10);    	
	    }
	    content = '<span title="' + value + '" class="note" >' + value + '</span>';
	}
    return content;
}
function showMoneyTips(value, row, index) {
	var m = formatMoney(value,row,index);
    return showTips(m);
}
//判断是否为时间格式 yyyy-MM-dd HH:mm:ss
function strDateTime(str){
	var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; 
	var r = str.match(reg); 
	if(r==null)return false; 
	var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]); 
	return (d.getFullYear()==r[1]&&
	(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7
	]);
}



</script>
</head>
<body style="height: 200%">
<div class="jianju">
<h3>会员账户报表</h3>

<div id="tb" style="padding:5px;height:auto">
<div style="margin-bottom:5px">
	<a id="export" href="#" class="easyui-linkbutton button" iconCls="icon-daochu">导出</a>
</div>
<hr/>
	<div>
	  <label style="margin-left:0px">会员手机号：</label><input id="tel" class="easyui-textbox" style="width:120px">
		<label style="margin-left:18px">会员姓名：</label><input id="memberName" class="easyui-textbox" style="width:110px">
		<a id="search" href="#" class="easyui-linkbutton button" style="margin-left:15px;" iconCls="icon-search">查询</a>	
			<br>
		<div id="pulldown" style="display: none;">
		<label style="margin-left:0px">开&nbsp;单&nbsp;中&nbsp;心：</label>
			
			<select id="kdzx" class="easyui-combobox" style="width: 100px" 
					mode="remote" url="${ctx}/member/findUserName?f=true" valueField="userAccount"
					textField="username" method="get" editable="false" panelHeight="auto">
				</select>
		<label style="margin-left:15px;">加入时间：</label>
			<input id="startTime" type="text" class="easyui-datebox" style="width:110px" editable="false"/>
			&nbsp;~&nbsp;
			<input id="endTime" type="text" style="width:110px" class="easyui-datebox" editable="false"/>
	</div>
		<div class="demo_line_01"><span class="line"></span> <span id="drop" style="font-size: 20px;margin-right:12px" class="glyphicon glyphicon-download"> </span><span class="line"></span></div>
	</div>
</div>

	<table id="tt" class="easyui-datagrid" 
		url=""
		title="" style="width:98%;minWidth:1000px;" 
		rownumbers="true" pagination="true"
		pageList="[200]" method="get"
		toolbar="#tb" singleSelect="true" pageSize="200"
		fitColumns="true" showFooter="true" rowStyler="rowStyle"
		onLoadSuccess:function(data){
                $(".note").tooltip({
                    onShow: function(){
                        $(this).tooltip('tip').css({ 
                            width:'300',
                            boxShadow: '1px 1px 3px #292929'       
                                             
                        });
                    }
                });
             } >
		<thead>
			<tr style="background:#148CCA;">
				<th data-options="field:'memberName',align:'left',formatter:showTips" style="width:8%">会员姓名</th>
				<th data-options="field:'cellPhone',align:'center',formatter:showTips" style="width:9%">会员手机号</th>
				<th data-options="field:'userName',align:'center',formatter:showTips" style="width:11%">开单中心</th>
				<th data-options="field:'totalIncome',align:'right' ,formatter:formatMoney,formatter:showMoneyTips" style="width:8%">总收益</th>
				<th data-options="field:'avaibleCash',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">余额</th>
				<th data-options="field:'cusumeCash',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">乐花</th>
				<th data-options="field:'investmentCash',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">贴心宝</th>
				<th data-options="field:'tax',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">税费</th>
				<th data-options="field:'rechagreCash',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">充值金额</th>
				<th data-options="field:'recommendAward',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">推荐奖</th>
				<th data-options="field:'a1Award',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">A1奖</th>
				<th data-options="field:'a2Award',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">A2奖</th>
				<th data-options="field:'a3Award',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">A3奖</th>
				<th data-options="field:'b1Award',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">B1奖</th>
				<th data-options="field:'b2Award',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">B2奖</th>
				<th data-options="field:'b3Award',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">B3奖</th>
				<th data-options="field:'dpBackAward',align:'right',formatter:formatMoney,formatter:showMoneyTips" style="width:8%">死点返还</th>
			</tr>
		</thead>
	</table>
	<div>
<table id="memberIncomeSum">
		<thead>
			<tr>
				<th style="width:5%">合计</th>
				<th style="width:5%">总收益</th>
				<th style="width:5%">余额</th>
				<th style="width:5%">乐花</th>
				<th style="width:5%">贴心宝</th>
				<th style="width:5%">税费</th>
				<th style="width:5%">充值金额</th>
				<th style="width:5%">推荐奖</th>
				<th style="width:5%">A1奖</th>
				<th style="width:5%">A2奖</th>
				<th style="width:5%">A3奖</th>
				<th style="width:5%">B1奖</th>
				<th style="width:5%">B2奖</th>
				<th style="width:5%">B3奖</th>
				<th style="width:5%">死点返还</th>
			</tr>
			<tr>
				<th style="width:11%"></th>
				<th id='totalSum'></th>
				<th id='avaibleSum'></th>
				<th id='cusumeSum'></th>
				<th id='investmentSum'></th>
				<th id='taxSum'></th>
				<th id='rechagreSum'></th>
				<th id='recommendSum'></th>
				<th id='a1Sum'></th>
				<th id='a2Sum'></th>
				<th id='a3Sum'></th>
				<th id='b1Sum'></th>
				<th id='b2Sum'></th>
				<th id='b3Sum'></th>
				<th id='dpBackSum'></th>
			</tr>
			
		</thead>
	</table>
</div>
 <div id="member-echarts" style="width: 800px;height:800px;"></div>
</div>
</body>
</html>